package com.xposed.aliproxy.xposed;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import com.xposed.aliproxy.utils.ActionUtil;
import com.xposed.aliproxy.utils.XposeUtil;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XC_MethodHook.MethodHookParam;
import de.robv.android.xposed.XposedBridge;

public class AliBalanceHookMethod extends XC_MethodHook {
    private Context context;

    public AliBalanceHookMethod(Context context) {
        this.context = context;
    }

    @Override
    protected void afterHookedMethod(MethodHookParam methodHookParam) throws Throwable {
        if (((View) methodHookParam.thisObject).getId() == 789184627) {
            String obj = methodHookParam.args[0].toString();
            if (obj.contains("元")) {
                obj = obj.substring(0, obj.length() - 1).trim().replaceAll(",", "");
                try {
                    Double.parseDouble(obj);
                    XposeUtil.xposedLog("aliBalance->", obj);
                    Intent intent = new Intent(ActionUtil.RECEIVER_ALI_BALANCE);
                    intent.putExtra("balance", obj);
                    this.context.sendBroadcast(intent);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                    return;
                } catch (Throwable th) {
                    XposedBridge.log(th);
                    return;
                }
            }
            return;
        }
        super.afterHookedMethod(methodHookParam);
    }
}
